package mex1;

/**
 * Mex2 - shows a simple way to coordinate 
 *        processing between two threads
 * @author Anthony Varghese
 */
public class Mex2 {
   private static int a;
   private static boolean ready;

   private class PrintThread extends Thread{
	   public void run(){
		   while (!ready)
			   yield();
		   System.out.println("    Print thread: a is " + a );
	   }
   }
   public static void main(String[] args) {
		a = 0; 
		ready = false;
		
		System.out.println(" Main: a is " + a );
		new Mex2().new PrintThread().start();

		try {
			System.out.println(" sleeping ..."); Thread.sleep(1000);
			a++;
			ready = true;
			
			System.out.println(" sleeping ..."); Thread.sleep(1000);			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(" Main: a is " + a );
	}
}
